package com.jp.knowledge.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.jp.knowledge.R;
import com.jp.knowledge.activity.BaseFragment;
import com.jp.knowledge.adapter.FragMentAdapter;
import com.jp.knowledge.view.CustomerViewpager;
import com.jp.knowledge.view.TabView;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;


/**
 * @author jiayen     2017-06-07 14:14:57
 */
public abstract class BaseTabFragment extends BaseFragment {


    private View mView;


    protected FragMentAdapter adapter;
    /***
     * 通讯录视图
     */
    @ViewInject(R.id.view_page)
    protected CustomerViewpager viewPager;

    @ViewInject(R.id.top)
    protected RelativeLayout  topLayout;

    @ViewInject(R.id.sort_btn)
    protected ImageView sortBtn;

    @ViewInject(R.id.tab_view)
    protected TabView tabView;

    public BaseTabFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mView =  inflater.inflate(R.layout.fragment_base_tab, container, false);
        x.view().inject(this,mView);
        init();
        return mView;
    }

    private void init(){
        initView();

        initTabLayout();

        if(showTopLayout()){
            topLayout.setVisibility(View.VISIBLE);
                initHead(mView);
        }else{
            topLayout.setVisibility(View.GONE);
        }
    }

    public void initTabLayout(){
        setTabNames();
        adapter = new FragMentAdapter(getFragmentManager(), getFragments());
        viewPager.setAdapter(adapter);
        tabView.setupWithViewPager(viewPager);
    }
    public abstract  void initView();
    /***
     * 显示   头部
     * @return
     */
    public boolean showTopLayout() {
        return  true;
    }

    /***
     * 获取fragment
     * @return
     */
    protected abstract List<Fragment> getFragments();
    public abstract void setTabNames();
}
